package com.helloandroid.vo

import com.helloandroid.MyApplication
import com.helloandroid.models.RelatedMatch
import com.helloandroid.msg.Msg
import java.lang.RuntimeException

enum class ZaoWanState(// 已经打卡
        val value: Int) {
    NormalDaKa(1),  // 正常打卡
    BuKa(2),  // 补卡
    TimeNotYet(3),  // 时间未到
    AlreadyDaKa(4);
}

// 表示早晚
enum class TimeType(val value: Int) {
    ZAO(1), WAN(2);
}

// 记录状态数据
data class ZWData(var time: TimeType = TimeType.ZAO, var state: ZaoWanState = ZaoWanState.TimeNotYet)


// 玩家信息
data class User(
        var user_id: Int,
        var coin: Int,  // 金币
        var money: Int, // 钱,需要除以10000
        var tx_count: Int, // 提现次数
        var tx_time_stamp: Long, // 提现时间戳
        var bs: Int, // 步数
        var bs_target: Int, // 步数目标
        var bs_sys: Int,  // 系统步数
//        var bs_time_stamp: Long = 0, // 上次步数更新时间戳
        var signed_count: Int, // 已经签到的次数
        var sign_time_stamp: Long, // 上次签到时间戳
//        val register_time: Long = 0,  // 用户注册时间
        var wx_id: String, // 微信id
        var wx_name: String, // 微信名字
        var wx_sex: Int, // 微信性别  0表示未知   1表示男性  2表示女性
        var wx_icon: String, // 微信图像地址
//        var wx_auth_time_stamp: Long = 0L // 微信授权时间戳
) {
    var loginTime: Long = -1


    fun copyFrom(other: User) {
        user_id = other.user_id
        coin = other.coin
        money = other.money
        tx_count = other.tx_count
        tx_time_stamp = other.tx_time_stamp
        bs = other.bs
        bs_target = other.bs_target
        bs_sys = other.bs_sys
        signed_count = other.signed_count
        sign_time_stamp = other.sign_time_stamp
        wx_id = other.wx_id
        wx_name = other.wx_name
        wx_sex = other.wx_sex
        wx_icon = other.wx_icon
        loginTime = other.loginTime
    }
}

data class BoardInfo(var cointime1: Long,
                     var cointime2: Long,
                     var cointime3: Long,
                     var dailyCoinState: Int,
                     var bsCount: Int, // 表示的是领奖时的步数
                     var firstUsed: Int
) : IDeepCopy<BoardInfo> {
    override fun deepCopy(): BoardInfo {
        return this.copy()
    }
}


// 奖励金币
data class CoinResponse(val total: Int, val added: Int)

// 奖励钱
data class MoneyAward(val count: Int = 0)


object SportName {
    const val Yuanditiao = "yuanditiao"
    const val Pingpangqiu = "pingpangqiu"
    const val Tizuqiu = "tizuqiu"
    const val Dalanqiu = "dalanqiu"
    const val Paobu = "paobu"
    const val Jianshencao = "jianshencao"
}

// 签到返回数据
data class SignResponse(val total: Int, val added: Int, val signedCount: Int, val signTimeMs: Long)

class ZhuanPanResponse(var result_id: Int, var count: Int, var addcount: Int, var restcount: Int, var usedcount: Int)

class ZpExtraAward(var total: Int, var added: Int)

data class ZaoWan(
        var zaoExecuted: Int = 0,
        var wanExecuted: Int = 0) : IDeepCopy<ZaoWan> {
    override fun deepCopy(): ZaoWan {
        return this.copy()
    }
}

// 喝水信息
data class HeShuiInfo(
        var w1: Int = 0,
        var w2: Int = 0,
        var w3: Int = 0,
        var w4: Int = 0,
        var w5: Int = 0,
        var w6: Int = 0,
        var w7: Int = 0,
        var w8: Int = 0
) : IDeepCopy<HeShuiInfo> {
    val stateArr: ArrayList<Int>
        get() = arrayListOf<Int>(w1, w2, w3, w4, w5, w6, w7, w8)

    // hsId 从1 开始
    fun setValueByHeShuiId(hsId: Int, value: Int) {
        when (hsId) {
            1 -> w1 = value
            2 -> w2 = value
            3 -> w3 = value
            4 -> w4 = value
            5 -> w5 = value
            6 -> w6 = value
            7 -> w7 = value
            8 -> w8 = value
            else -> throw RuntimeException("unknow hsId:$hsId")
        }
    }

    override fun deepCopy(): HeShuiInfo {
        return this.copy()
    }
}

// 吃饭补贴信息
data class ChiFanInfo(var zaocan: Int = 0,
                      var wucan: Int = 0,
                      var xiawucha: Int = 0,
                      var wancan: Int = 0,
                      var xiaoye: Int = 0) : IDeepCopy<ChiFanInfo> {
    val stateArr: ArrayList<Int>
        get() = arrayListOf<Int>(zaocan, wucan, xiawucha, wancan, xiaoye)

    // 注意 cfId 是从1开始的
    /**
     * local:  true -> 表示本地更新,不一定真的打卡成功,只是为了显示
     *         false -> 需要更新 sharePerference
     */
    fun setValueByChiFanId(cfId: Int, value: Int, local: Boolean = true) {
        when (cfId) {
            1 -> {
                zaocan = value
                if (!local) {
                    MyApplication.app.serverProxy?.sendMsgToServer(Msg.C2S_ZaoDaKaSuccess, "")
                }
            }
            2 -> {
                wucan = value
                if (!local) {
                    MyApplication.app.serverProxy?.sendMsgToServer(Msg.C2S_ZhongDaKaSuccess, "")
                }
            }
            3 -> {
                xiawucha = value
                if (!local) {
                    MyApplication.app.serverProxy?.sendMsgToServer(Msg.C2S_XiaWuDaKaSuccess, "")
                }
            }
            4 -> {
                wancan = value
                if (!local) {
                    MyApplication.app.serverProxy?.sendMsgToServer(Msg.C2S_WanDaSuccess, "")
                }
            }
            5 -> {
                xiaoye = value
                if (!local) {
                    MyApplication.app.serverProxy?.sendMsgToServer(Msg.C2S_XiaoyeDaKaSuccess, "")
                }
            }
            else -> throw RuntimeException("unknow cfId:$cfId")
        }
    }

    fun getValueByChiFanId(cfId: Int): Int {
        return when (cfId) {
            1 -> zaocan
            2 -> wucan
            3 -> xiawucha
            4 -> wancan
            5 -> xiaoye
            else -> throw RuntimeException("unknow cfId:$cfId")
        }
    }

    override fun deepCopy(): ChiFanInfo {
        return this.copy()
    }
}


// 每日运动数据
data class SportItem(var state: Int, var start: Long) : IDeepCopy<SportItem> {
    override fun deepCopy(): SportItem {
        return this.copy()
    }
}

data class MeiRiYunDongInfo(
        val map: HashMap<String, SportItem>
) : IDeepCopy<MeiRiYunDongInfo> {
    fun getSportItem(key: String): SportItem {
        return map[key]!!
    }

    override fun deepCopy(): MeiRiYunDongInfo {
        val newMap = HashMap<String, SportItem>()
        val iter = map.iterator()
        while (iter.hasNext()) {
            val entry = iter.next()
            newMap[entry.key] = entry.value.deepCopy()
        }
        return MeiRiYunDongInfo(newMap)
    }
}

enum class SportState(val value: Int) {
    Geted(1), // 已开始 已完成 已领取
    Getable(2), // 已开始,已完成,未领取
    UnCompleted(3), // 已开始,未完成
    UnStarted(4), // 未开始
}

data class SportDataItem(val id: Int, val key: String, val iconRes: Int, val title: String, val coinCount: Int, val energyCount: Int, val timeMinutes: Int, val gifRes: Int) {
    val desc: String = "运动${timeMinutes}分钟可以消耗${energyCount}卡路里"
}

data class BsInfo(var state: Int, val coin: Int, var bs: Int) : IDeepCopy<BsInfo> {
    override fun deepCopy(): BsInfo {
        return this.copy()
    }
}

// 赚赚里面 上报后的返回
data class TaskReportResponse(val count: Int, val state: Int)

data class HbyInfo(var lastTimeMs: Long, var count: Int) : IDeepCopy<HbyInfo> {
    override fun deepCopy(): HbyInfo {
        return this.copy()
    }
}


// 红包雨领奖结果
data class HbyAwardResponse(var added: Int, var total: Int, var count: Int)


data class CoinAndMoney(val coin: Int, val money: Int)


data class TxItem(val amount: Int, val timeStamp: Long)
data class TxInfo(val arr: ArrayList<TxItem>) : IDeepCopy<TxInfo> {
    override fun deepCopy(): TxInfo {
        val newArr = ArrayList<TxItem>()
        arr.forEach {
            newArr.add(it.copy())
        }
        return TxInfo(newArr)
    }
}


// 集福奖励返回
data class JFAwardResponse(val count: Int,val resultId:Int,val restCount:Int)


data class TTMatchInfo(
        val matchId:Int,
        val title:Int,
        val type:Int, // 3000 or 8000
        var people:Int, // 真实参与人数
        val peopleOK:Int, //  真实完成人数
        var robots:Int, // 机器人数量
        var robotsOKRate:Int, // 机器人完成率
        var matchState:MatchState, // 比赛状态
        var totalMoney:Float, // 总奖池
):Comparable<TTMatchInfo>{

    companion object{
        const val Negitive = -1
        const val Positive = 1

        // 比赛类型
        const val M3000 = 3000
        const val M8000 = 8000
    }

    override fun compareTo(other: TTMatchInfo): Int {
        return  other.title - title
    }

    fun isGetable(lst:List<RelatedMatch>):Boolean{
        if(matchState != MatchState.Ended){
            return false
        }

        val relatedMatch = lst.find { it.matchId == matchId }
        return relatedMatch != null && relatedMatch.state == UserMatchState.Completed
    }

    fun totalPeople() = people + robots

    fun totalCompletedPeople() :Int{
        return peopleOK + (robots * robotsOKRate / 100f).toInt()
    }
}

